'''
条件边的使用
1.创建保存图的状态的字典
2.创建智能体
3.创建条件智能体
4.创建带状态的图
5.创建节点 节点和智能体绑定
6.添加边和条件边
7.编译图
8.使用：通过图执行智能体和管理  invoke
'''

from typing import TypedDict
from langgraph.graph import START,END,StateGraph

class State(TypedDict):
    foo:int

def agent_01(state):
    return {"foo":state["foo"]+1}

def condi(state):
    if state['foo']>10:
        return END
    else:
        return "node_01"

builder = StateGraph(State)

builder.add_node("node_01",agent_01)
builder.add_edge(START,"node_01")
builder.add_conditional_edges("node_01",condi,{"node_01":"node_01",END:END})

graph = builder.compile()

r = graph.invoke({"foo":10})
print(r)

graph.get_graph().draw_mermaid_png(output_file_path="cond_02.png")
